<?php
include_once(ICE_ROOTPATH."/../IceConfig.php");
include_once(ICE_ROOTPATH."/../IceException.php");
include_once(ICE_ROOTPATH."/../context/ContextFactory.php");

/**
 *  
 * @author   iCer <iCer@justdn.com> created on Thu Jul 06 11:41:15 JST 2006
 * @version  $Id$
 */
class ActionFactory {
	
	public function buildAction() {
		$request = ContextFactory::getInstance()->getRequest();
		$moduleName = $request->has("module")?$request->get("module"):IzzConfig::$DEFAULT_MODULE;
		//设置module路径
		if (!isset($moduleName) || $moduleName=='' || $moduleName==null){
			$moduleName = '.';
		} else {
			$moduleName = str_replace('.', '/', $moduleName);
		}
		
		$actionName = $request->has("action")?$request->get("action"):IzzConfig::$DEFAULT_ACTION;
		$actionName = strtoupper(substr($actionName, 0, 1)).substr($actionName,1)."Action";
		if (!isset($actionName) || $actionName=='' || $actionName==null) throw new IceException("no action request");
		
		$actionPath = IzzConfig::$APPLICATION_ROOT.'/'.IzzConfig::$ACTION_PATH.'/'.$moduleName.'/'.$actionName.".php";
		if (!file_exists($actionPath)) throw new IceException("action file($actionPath) not find");
		
		include_once($actionPath);
		if (!class_exists($actionName)) throw new IceException("action class not defined");
		
		$actionInstance = new $actionName(); 
		
		return $actionInstance;
	}

}
?>
